/*
** Line Protocol Connection Library
** Copyright (C) 2008 Eric Day
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to:
** Free Software Foundation, Inc.
** 51 Franklin Street, Fifth Floor,
** Boston, MA  02110-1301, USA
*/

#ifndef _LPC_PRIV_H
#define _LPC_PRIV_H

#include "config.h"

#if HAVE_ERRNO_H
#include <errno.h>
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#if HAVE_NETDB_H
#include <netdb.h>
#endif
#if HAVE_STDARG_H
#include <stdarg.h>
#endif
#include <stdio.h>
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif

#include "lpc.h"

/* limits on variables */
#define LPC_STATUS_LEN 64
#define LPC_BUF_LEN    16384

/* flags for LPC */
#define LPC_FLAGS_CONNECTING 0x00000001
#define LPC_FLAGS_CONNECTED  0x00000002

/* macro to help with error checking */
#define LPC_RET_CHECK(__lpc, __check, __func, __errno) { \
    if (__check) \
    { \
        lpc_close(__lpc); \
        if (__errno > 0) \
        { \
            fprintf(stderr, __func ":%d:%s\n", __errno, strerror(__errno)); \
            return __errno; \
        } \
        fprintf(stderr, __func ":%d\n", __errno); \
        return -1; \
    } }

/*
** structs
*/

struct _LPC
{
    struct pollfd      *pfd;
    struct sockaddr_in  sin;
    int                 flags;
    char                status[LPC_STATUS_LEN];
    char                read_buf[LPC_BUF_LEN];
    int                 read_len;
    char                write_buf[LPC_BUF_LEN];
    int                 write_len;
};

#endif /* _LPC_PRIV_H */
